//
//  LFNetService.m
//  联付商圈
//
//  Created by 韩佳睿 on 2017/9/29.
//  Copyright © 2017年 lianfu. All rights reserved.
//

#import "LFNetService.h"

NSString * const LPaypassword  = @"zfmm?"; 


@interface LFNetService()

@property (nonatomic, strong)AFHTTPSessionManager *httpsSessionManager;

@end

@implementation LFNetService

+ (instancetype)sharedInstance
{
    static dispatch_once_t once;
    static LFNetService *sharedInstance;
    dispatch_once(&once, ^{
        sharedInstance = [[self alloc] init];
    });
    
    return sharedInstance;
}

- (NSURLSessionDataTask *)getActionWithActionURLName:(NSString *)urlName
                                          parameters:(NSDictionary *_Nullable)params
                                            complete:(LFAPIResponseBlock)complete {
    self.httpsSessionManager = [AFHTTPSessionManager manager];
    self.httpsSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    self.httpsSessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain", nil];
    self.httpsSessionManager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
    self.httpsSessionManager.securityPolicy.allowInvalidCertificates = YES;
    
    return [self.httpsSessionManager GET:[Host stringByAppendingString:@"zfmm?"] parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        #if API_DEBUG
        NSLog(@"request response:%@", responseObject);
        #endif
        NSError *error = nil;
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        if (complete) {
            complete(dic, error);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        id resp = nil;
        if (complete) {
            complete(resp, error);
        }
    }];
}

- (AFHTTPSessionManager *)httpsSessionManager {
    if (!_httpsSessionManager) {
        _httpsSessionManager = [AFHTTPSessionManager manager];
    }
    return _httpsSessionManager;
}

@end
